// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using Antlr4.Runtime.Tree;
using Microsoft.Extensions.DependencyInjection;
using static Common.Grammar.Antlr.CommonParser;

namespace SnapObjects.Expressions
{
    public static partial class ExpressionsServiceCollectionExtensions
    {
        internal static IServiceCollection AddExpressionCore<T>(this IServiceCollection services)
        {
            services.AddLogging();

            services.AddTransient<ICacheProvider, CacheProvider>();

            services.AddTransient<IExpressionVisitor<T>, ExpressionVisitor<T>>();

            return services;
        }

        private static IServiceCollection AddVisitors<T>(this IServiceCollection services)
        {
            services.AddTransient<INodeExpressionVisitor<T>, AdditiveExpressionVisitor<T, Expression_additiveContext>>();
            services.AddTransient<INodeExpressionVisitor<T>, AndorExpressionVisitor<T, Expression_andorContext>>();
            services.AddTransient<INodeExpressionVisitor<T>, AtomExpressionVisitor<T, Expression_atomContext>>();
            services.AddTransient<INodeExpressionVisitor<T>, LiteralExpressionVisitor<T, LiteralContext>>();
            services.AddTransient<INodeExpressionVisitor<T>, MultiplicativeExpressionVisitor<T, Expression_multiplicativeContext>>();
            services.AddTransient<INodeExpressionVisitor<T>, NotExpressionVisitor<T, Expression_notContext>>();
            services.AddTransient<INodeExpressionVisitor<T>, ParenthesesExpressionVisitor<T, Expression_parenthesesContext>>();
            services.AddTransient<INodeExpressionVisitor<T>, PrimaryExpressionVisitor<T, Expression_primaryContext>>();
            services.AddTransient<INodeExpressionVisitor<T>, RelationalExpressionVisitor<T, Expression_relationalContext>>();
            services.AddTransient<INodeExpressionVisitor<T>, IdentifierExpressionVisitor<T, IdentifierContext>>();
            services.AddTransient<INodeExpressionVisitor<T>, TerminalExpressionVisitor<T, ITerminalNode>>();
            services.AddTransient<INodeExpressionVisitor<T>, NewExpressionVisitor<T, Expression_newContext>>();
            services.AddTransient<INodeExpressionVisitor<T>, TernaryExpressionVisitor<T, Expression_ternaryContext>>();
            services.AddTransient<INodeExpressionVisitor<T>, UnitaryExpressionVisitor<T, Expression_unitaryContext>>();
            services.AddTransient<INodeExpressionVisitor<T>, OtherFunctionExpressionVisitor<T, Expression_other_functionContext>>();
            services.AddTransient<INodeExpressionVisitor<T>, CaretExpressionVisitor<T, Expression_caretContext>>();
            services.AddTransient<INodeExpressionVisitor<T>, NewExpressionVisitor<T, Expression_newContext>>();

            return services;
        }
    }
}
